package com.centriole.serviceLog.controller;

import com.centriole.common.component.ContextUtils;
import com.centriole.serviceLog.entity.Log;
import com.centriole.serviceLog.service.Impl.LogServiceImpl;
import com.centriole.serviceLog.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class LogController {

    @Autowired
    private LogService logService;

    @RequestMapping(value="/list")
    @CrossOrigin(allowCredentials="true", allowedHeaders="*", methods={RequestMethod.POST}, origins="*")
    @ResponseBody
    public Map<String,Object> getLogData(Log log){
        Map<String,Object> map = new HashMap<String,Object>();
        List<Log> list = logService.listByCondition(log);
        map.put("Rows", list);
        return map;
    }

    @RequestMapping("/doLog")
    @ResponseBody
    public Boolean doLog(Log log){
        //log.setDate(new Date());
        return logService.save(log) ;
    }

}
